{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "from __future__ import print_function, division\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "pd.set_option('display.max_columns', 500)\n",
    "import json\n",
    "import sys, os\n",
    "from shutil import copyfile\n",
    "sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..'))) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1>Write HTML derm and clinic pages</h1>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from derm7pt.utils import html_image_src\n",
    "dir_write_html = '/local-scratch/jer/data/argenziano/release_v0'\n",
    "dir_images = \"images\"\n",
    "metadata_csv= os.path.join(dir_write_html, 'meta/meta.csv')\n",
    "meta_df = pd.read_csv(metadata_csv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "html_header = '''\n",
    "<html lang=\"en\">\n",
    "<head>\n",
    "  <meta charset=\"utf-8\">\n",
    "  <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\" integrity=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"anonymous\">\n",
    "  <style type=\"text/css\"></style>\n",
    "</head>\n",
    "<body>\n",
    "<div class=\"container-fluid\" style=\"max-width:800px\">\n",
    "<div class=\"row\">\n",
    "'''\n",
    "\n",
    "html_footer = '''\n",
    "</div>\n",
    "</div>\n",
    "</body>\n",
    "</html>\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Derm HTML page.\n",
    "derm_paths = [os.path.join(dir_images, derm_path) for derm_path in meta_df.derm]\n",
    "html_derm_image = html_image_src(derm_paths)\n",
    "html_derm_out = html_header + html_derm_image + html_footer\n",
    "with open(os.path.join(dir_write_html, \"derm.html\"), \"w\") as text_file:\n",
    "    text_file.write(html_derm_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Clinic HTML page.\n",
    "clinic_paths = [os.path.join(dir_images, img_path) for img_path in meta_df.clinic]\n",
    "html_clinic_image = html_image_src(clinic_paths)\n",
    "html_clinic_out = html_header + html_clinic_image + html_footer\n",
    "with open(os.path.join(dir_write_html, \"clinic.html\"), \"w\") as text_file:\n",
    "    text_file.write(html_clinic_out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
